/**
 * 火车服务数据交互统一入口
 */
import axios from 'axios';
class Train {

//火车热门城市 or 城市选择
  static trainCityList(params, success, fail) {
    axios.get('train/search/cityList.json', {
      params: params
    }).then(res => {
      success(res.data);
    }).catch(fail);
  }

//火车列表显示
  static getTrainList(params, success, fail) {
    axios.get('train/search/list.json', {
      params: params
    }).then(res => {
      success(res.data);
    }).catch(fail);
  }

  //创建订单
  static createOrder(data, success, fail) {
    axios.post('train/booking/createOrder.json', data).then(res => {
      success(res.data);
    }).catch(fail);
  };

  //取消订单
  static cancelOrder(orderId, success, fail) {
    axios.get('train/order/cancel.json?orderId=' + orderId).then(res => {
      success(res.data);
    }).catch(fail);
  };

  //退款订单
  static refundOrder(data, success, fail) {
    axios.post('train/order/refund.json', data).then(res => {
      success(res.data);
    }).catch(fail);
  };

  //取消审批
  static recallOrder(orderId, success, fail) {
    if (!orderId) {
      fail();
    }
    axios.get('order/cacelAuthorize/' + orderId + '.json').then(res => {
      success(res.data);
    }).catch(fail);
  };
}
export default Train;
